//
//  LHImageTextDetailView.m
//  lehuotest
//
//  Created by ice on 2017/1/4.
//  Copyright © 2017年 QF. All rights reserved.
//

#import "LHImageTextDetailView.h"
#import <WebKit/WebKit.h>
@interface LHImageTextDetailView()<UIWebViewDelegate,UIScrollViewDelegate>

@property (nonatomic, weak) IBOutlet UILabel *upShowLabel;

@property (nonatomic, strong) NSString *url;
@end

@implementation LHImageTextDetailView
+ (id)loadFromNib
{
    NSString *xibName = NSStringFromClass([self class]);
    return [[[NSBundle mainBundle] loadNibNamed:xibName owner:nil options:nil] firstObject];
}

-(void) awakeFromNib
{
    [super awakeFromNib];
    self.webView.backgroundColor = [UIColor lightGrayColor];
    self.webView.delegate = self;
    self.webView.scrollView.delegate = self;
    self.upShowLabel.alpha = 0;
}

-(void) setShowText:(NSString *)showText
{
   self.upShowLabel.text = showText;
}
-(void) setAlphaValue:(float)alphaValue
{
    self.upShowLabel.alpha =  alphaValue;
}
-(void) loadRequestUrl:(NSString *)url
{
    _url = url;
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
}

-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    return YES;
}

-(void) webViewDidFinishLoad:(UIWebView *)webView
{
    if ([self.delegate respondsToSelector:@selector(LHImageTextDetailView:loadRequest:isSuccess:)]){
        [self.delegate LHImageTextDetailView:self loadRequest:self.url isSuccess:YES];
    }
}

-(void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    if ([self.delegate respondsToSelector:@selector(LHImageTextDetailView:loadRequest:isSuccess:)]){
        [self.delegate LHImageTextDetailView:self loadRequest:self.url isSuccess:NO];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
